package org.kyw.pay.service.impl;

import org.kyw.basic.exception.BusinessException;
import org.kyw.basic.service.impl.BaseServiceImpl;
import org.kyw.pay.domain.AlipayInfo;
import org.kyw.pay.domain.PayBill;
import org.kyw.pay.mapper.AlipayInfoMapper;
import org.kyw.pay.service.IAlipayInfoService;
import org.kyw.pay.utils.AlipayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AplipayInfoServiceImpl extends BaseServiceImpl<AlipayInfo> implements IAlipayInfoService {
    @Autowired
    private AlipayInfoMapper alipayInfoMapper;
    @Override
    public AlipayInfo getByShopId(Long shop_id) {
        return alipayInfoMapper.loadByShopId(shop_id);
    }

    @Override
    public String pay(PayBill bill) {
        if(bill == null || bill.getShop_id() == null){
            throw new BusinessException("bill有问题");
        }
        AlipayInfo info = alipayInfoMapper.loadByShopId(bill.getShop_id());
        return AlipayUtils.pay(bill, info);
    }

}
